package tree;

import javax.swing.*;
import java.awt.*;
import java.util.LinkedList;

public class Node
{
    String all="";
    public Token tok;
    private LinkedList<Node> cldList = new LinkedList<Node>();
    public Node(Token tok)
    { this.tok = tok; }//leaf

    public void addCld(Node nd)
    {
        cldList.add(nd);
    }

    public String treePrint()
    {
        treePrintLevel(this, 0);
        return all;
    }

    private void treePrintLevel(Node nd, int level)
    {
        int i;
        int num=0;
        if(nd!=null) //root
        {
            for(i=0;i<4*level;i++) {
                all=all+".";
                num++;
                System.out.print("=");
            }
            String s = nd.tok.emitToken();
            all=all+s+"\n";
        }
        if(nd.cldList.isEmpty()==false) //recursive
        {
            for (Node currNd: nd.cldList) {
                treePrintLevel(currNd, level+1);
            }
        }
    }
}